import Vue from 'vue'
// import Vuex from 'vuex'
import Vuex from '@/plugins/lua-vuex/index'

Vue.use(Vuex)

const loggerPlugin = (store) => {
  store.subscribe((mutation, state) => {
    console.log("Logger This:", mutation.payload);
  });
}

export default new Vuex.Store({
  state: {
    name: 'helloVueX',
    auth: {
      token: 'eyJpZCI6MTA4MzMxLCJ1c2VybmFtZSI6Imxvbmd4aWFvYmFpIiwiZXhwIjoxNjAzNDI2NDk4fQ',
      name: 'longxiaobai',
      createdAt: '2020-08-06T06:34:29.912Z'
    }
  },
  getters: {
    compose(state) {
      return `This is ${state.name}`;
    },
    wrapper(state) {
      return state.auth;
    }
  },
  mutations: {
    setName(state, payload) {
      state.name = payload;
    },
    setAuth(state, payload) {
      state.auth = payload;
    }
  },
  actions: {
    setNameAction(context, payload) {
      setTimeout(() => {
        context.commit('setName', payload);
      }, 2000);
    }
  },
  plugins: [loggerPlugin]
})
